package com.grandprixsw.evmsmobile;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

public class DefinitionActivity extends ListActivity {
	private String[] terminologyAbbrs;
	private String[] terminologies;
	private String[] terminologyDefinitions;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.definition_terminologies_list);
        
        terminologyAbbrs = getResources().getStringArray(R.array.terminology_abbrs_array);
        terminologies = getResources().getStringArray(R.array.terminologies_array);
        terminologyDefinitions = getResources().getStringArray(R.array.term_definitions_array);
        setListAdapter(new TerminologyArrayAdapter(this, terminologyAbbrs, terminologies));
    }
    
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		showDialog(position);
	}
	
    @Override
    public Dialog onCreateDialog(int id) {
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
	
		dialogBuilder.setTitle(terminologies[id]);
		dialogBuilder.setNegativeButton(R.string.close_btn, 
				new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {}
		});
		

		LayoutInflater inflater = getLayoutInflater();  
		View terminologyDefinitionsView = inflater.inflate(R.layout.definition_terminology_view, (ViewGroup) findViewById(R.layout.definition_terminologies_list), false);

		TextView terminologyDefinition = (TextView) terminologyDefinitionsView.findViewById(R.id.terminology_definition_text);
		terminologyDefinition.setText(terminologyDefinitions[id]);
		
		dialogBuilder.setView(terminologyDefinitionsView);
		
		Dialog dlg = dialogBuilder.create();
		 
		return dlg;
    }    
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	super.onCreateOptionsMenu(menu);
    	
    	return GlobalOptionsMenu.CreateMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	return GlobalOptionsMenu.MenuChoice(this, item);
    }
    
}
